// Problem: 
// Contest: 
// URL: 
// Memory Limit: 
// Time Limit: 
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
struct pos
{
	int x,y;
	pos(int xx,int yy)
	{
		x=xx,y=yy;
	}
};
int dx[4]={0,0,-1,1};
int dy[4]={1,-1,0,0};
signed main()
{
	int n,m,ans=0;
	cin>>n>>m;
	vector<vector<char>> v(n+1,vector<char>(m+1));
	vector<vector<bool>> vis(n+1,vector<bool>(m+1));
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>v[i][j];
	queue<pos> q;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(v[i][j]!='0'&&vis[i][j]==0)ans++;
			else continue;
			q.push(pos(i,j));
			while(!q.empty())
			{
				pos tmp=q.front();
				q.pop();
				int x=tmp.x,y=tmp.y;
				if(x<1||x>n||y<1||y>m||v[x][y]=='0'||vis[x][y])continue;
				vis[x][y]=1;
				for(int i=0;i<4;i++)
				{
					q.push(pos(x+dx[i],y+dy[i]));
				}
			}
		}
	cout<<ans;
	return 0;
}
